package cn.walls1717.ggkt.vod.controller;


import cn.walls1717.ggkt.model.vod.Video;
import cn.walls1717.ggkt.result.Result;
import cn.walls1717.ggkt.vod.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 课程视频相关接口
 *
 * @author walls1717
 * @since 2022/07/14
 */
@Api(tags = "课程小结（课时）")
@RestController
@RequestMapping("/admin/vod/video")
public class VideoController {

    @Autowired
    private VideoService videoService;

    @ApiOperation("根据查询视频")
    @GetMapping("get/{id}")
    public Result<Video> getVideoById(@PathVariable Long id) {
        Video video = videoService.getById(id);
        return Result.success(video);
    }

    @ApiOperation("新增")
    @PostMapping("save")
    public Result<?> saveVideo(@RequestBody Video video) {
        videoService.save(video);
        return Result.success();
    }

    @ApiOperation("修改")
    @PutMapping("update")
    public Result<?> updateVideoById(@RequestBody Video video) {
        // 设置更新日期为当前时间
        video.setUpdateTime(new Date());
        videoService.updateById(video);
        return Result.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("remove/{id}")
    public Result<?> deleteVideo(@PathVariable Long id) {
        videoService.deleteVideoById(id);
        return Result.success();
    }

}

